import Vue from 'vue'
import VueRouter from 'vue-router'
const Film = () => import('../views/Film.vue')
const Cinema = () => import('../views/Cinema.vue')
const Center = () => import('../views/Center.vue')
const NowPlaying = () => import('../views/film/NowPlaying.vue')
const ComingSoon = () => import('../views/film/ComingSoon.vue')
const Detail = () => import('../views/Detail.vue')
const City = () => import('../views/City.vue')
const CinemaSearch = () => import('../views/CinemaSearch.vue')
const Login = () => import('../views/Login.vue')
const CinemaDetail = () => import('../views/CinemaDetail.vue')

Vue.use(VueRouter)


// 下列三行代码是方式路由跳转时点击多次报出错误，进行错误抛出
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const routes = [
  {
    path: '/',
    redirect: '/film'
  },
  {
    path: '/film',
    component: Film,
    meta: {
      ifShowTabbar: true
    },
    children: [
      {
        path: '/',
        redirect: '/film/nowplaying'
      },
      {
        path: 'nowplaying',
        component: NowPlaying,
        meta: {
          ifShowTabbar: true
        },
      },
      {
        path: 'comingsoon',
        component: ComingSoon,
        meta: {
          ifShowTabbar: true
        },
      },
    ]
  },
  {
    path: '/cinema',
    component: Cinema,
    meta: {
      ifShowTabbar: true
    }
  },
  {
    path: '/center',
    component: Center,
    meta: {
      ifShowTabbar: true
    }
  },
  {
    path: '/detail/:myid',
    component: Detail
  },  
  {
    path: '/city',
    component: City
  },
  {
    path: '/cinemas/search',
    component: CinemaSearch
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/cinemadetail/:id',
    component: CinemaDetail
  }
]

const router = new VueRouter({
  routes,
})



export default router